package edu.umd.ion.wavemeter.server;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import edu.umd.ion.wavemeter.service.CalibrationResult;


@SuppressWarnings("serial")
@Entity(name="CalibrationResult")
@Table(name = "CalibrationResult") //Name of the entity
@NamedQueries({
    @NamedQuery(name="RelevantCalibrations",
        query="SELECT x FROM CalibrationResult x where x.ReturnValue=0 order by x.CalibrationDate desc")
})
public class PersistentCalibrationResult implements Serializable {
	@Id //signifies the primary key
	@Column(name = "id", nullable = false)
	@GeneratedValue(strategy = GenerationType.SEQUENCE)
	private long id;

	@Column(name="WavelengthBefore")
	private double WavelengthBefore;
	
	@Column(name="WavelengthAfter")
	private double WavelengthAfter;
	
	@Column(name="ReturnValue")
	private int ReturnValue;
	
	@Column(name="CalibrationDate")
	private Date CalibrationDate;
	
	@Column(name="Channel")
	private int Channel;
	
	@Column(name="UserName")
	private String UserName;
	
	@Column(name="HostName")
	private String HostName;
	
	public void set(CalibrationResult o) {
		CalibrationDate = o.CalibrationDate;
		Channel = o.Channel;
		HostName = o.HostName;
		ReturnValue = o.ReturnValue;
		UserName = o.UserName;
		WavelengthAfter = o.WavelengthAfter;
		WavelengthBefore = o.WavelengthBefore;		
	}

	public void set(PersistentCalibrationResult o) {
		CalibrationDate = o.CalibrationDate;
		Channel = o.Channel;
		HostName = o.HostName;
		ReturnValue = o.ReturnValue;
		UserName = o.UserName;
		WavelengthAfter = o.WavelengthAfter;
		WavelengthBefore = o.WavelengthBefore;		
	}
	
	public CalibrationResult plain() {
		CalibrationResult r = new CalibrationResult();
		r.CalibrationDate = new Date(CalibrationDate.getTime());
		r.Channel = Channel;
		r.HostName = new String(HostName);
		r.ReturnValue = ReturnValue;
		r.UserName = new String(UserName);
		r.WavelengthAfter = WavelengthAfter;
		r.WavelengthBefore = WavelengthBefore;
		return r;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public double getWavelengthBefore() {
		return WavelengthBefore;
	}

	public void setWavelengthBefore(double wavelengthBefore) {
		WavelengthBefore = wavelengthBefore;
	}

	public double getWavelengthAfter() {
		return WavelengthAfter;
	}

	public void setWavelengthAfter(double wavelengthAfter) {
		WavelengthAfter = wavelengthAfter;
	}

	public int getReturnValue() {
		return ReturnValue;
	}

	public void setReturnValue(int returnValue) {
		ReturnValue = returnValue;
	}

	public Date getCalibrationDate() {
		return CalibrationDate;
	}

	public void setCalibrationDate(Date calibrationDate) {
		CalibrationDate = calibrationDate;
	}

	public int getChannel() {
		return Channel;
	}

	public void setChannel(int channel) {
		Channel = channel;
	}

	public String getUserName() {
		return UserName;
	}

	public void setUserName(String userName) {
		UserName = userName;
	}

	public String getHostName() {
		return HostName;
	}

	public void setHostName(String hostName) {
		HostName = hostName;
	}	
}
